// packageTab/pages/Bankcard/Bankcard.js
import {
  bank_save,
  bank_query
} from '../../../utils/imapi';
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		name: '', //姓名
		Where_it_is: '', //开户行
		countImg: '', //图片
		card_number: '', //卡号
		is_upload: false,
		hiddenmodalput_name: true,
		hiddenmodalput_code:true,
		hiddenmodalput_itis:true,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad:async function(options) {
        var data=await bank_query({page_index:1,page_size:10});

		this.setData({
			name:data.data[0].name,
			Where_it_is:data.data[0].card_no, 
			card_number:data.data[0].card_name, 
			countImg:data.data[0].bank_zm_img
		})
	},
	conname(e){
		this.setData({
			name:e.detail.value
		})
	},
	conname_1(e){
		this.setData({
			card_number:e.detail.value
		})
	},
	conname_2(e){
		this.setData({
			Where_it_is:e.detail.value
		})
	},
	upLoad() {
		var that = this;
		this.is_upload = true;
		wx.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: async function(res) {
				console.log(res);
				const tempFilePaths = res.tempFilePaths[0]
				that.is_upload = false;
				that.setData({
					countImg: tempFilePaths
				})
			}
		})
	},
	name_mode() {
		this.setData({
			hiddenmodalput_name: !this.data.hiddenmodalput_name
		})
	},
	name_mode_1() {
		this.setData({
			hiddenmodalput_code: !this.data.hiddenmodalput_code
		})
	},
	name_mode_2() {
		this.setData({
			hiddenmodalput_itis: !this.data.hiddenmodalput_itis
		})
	},
	//取消按钮
	cancel: function() {
		this.setData({
			hiddenmodalput_name: !this.data.hiddenmodalput_name
		})
	},
	//确认
	confirm: function() {
		console.log(this.data.name);
		this.setData({
			hiddenmodalput_name: !this.data.hiddenmodalput_name
		})
	},
	//取消按钮
	cancel_1: function() {
		this.setData({
			hiddenmodalput_code: !this.data.hiddenmodalput_code
		})
	},
	//确认
	confirm_1: function() {
		console.log(this.data.name);
		this.setData({
			hiddenmodalput_code: !this.data.hiddenmodalput_code
		})
	},
	//取消按钮
	cancel_2: function() {
		this.setData({
			hiddenmodalput_itis: !this.data.hiddenmodalput_itis
		})
	},
	//确认
	confirm_2: function() {
		console.log(this.data.name);
		this.setData({
			hiddenmodalput_itis: !this.data.hiddenmodalput_itis
		})
	},
	async quren(){
		if(!this.data.name){
			wx.showModal({
						title: '提示',
						content: '您还没有输入姓名',
						success: function(res) {
							
						}
					})
			return;
		}
		if(!this.data.card_number){
			wx.showModal({
						title: '提示',
						content: '您还没有输入卡号',
						success: function(res) {
							
						}
					})
			return;
		}
		if(!this.data.Where_it_is){
			wx.showModal({
						title: '提示',
						content: '您还没有输入开户行',
						success: function(res) {
							
						}
					})
			return;
		}
		if(!this.data.countImg){
			wx.showModal({
						title: '提示',
						content: '您还没有输入银行卡照片',
						success: function(res) {
							
						}
					})
			return;
		}
		
		const res=await bank_save({
			name:this.data.name,
			card_no:this.data.card_number,
			card_name:this.data.Where_it_is,
			bank_zm_img:this.data.countImg,
			bank_fm_img:"",
			card_type:'1'
		});
		
		console.log(res);
		
		if(res.code==0){
			wx.navigateBack({
			  delta: 1
			})
		}
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
